package com.lenovo.manufacture.module;

import android.annotation.SuppressLint;
import android.os.Bundle;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.lenovo.manufacture.Adapter.recAdapter;
import com.lenovo.manufacture.R;

import com.lenovo.manufacture.net.BaseActivity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import butterknife.BindView;
import butterknife.ButterKnife;

public class module7 extends BaseActivity {

    @BindView(R.id.m7_rv)
    RecyclerView m7Rv;
    List<Map<String, String>> qualities;
    List<Map<String, String>> car;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_module7);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        async(data.getcartype(), v -> {
            car = v.getData();
            async(BaseActivity.data.getUserQuality(), v1 -> {
                qualities = v1.getData();
                initview();
            });
        });
    }

    @SuppressLint("NewApi")
    private void initview() {
        List<String> list = new ArrayList<>();
        qualities.forEach(quality -> {
            Map<String, String> carTypeId = car.get(Integer.valueOf(quality.get("carTypeId")));
            list.add(quality.get("id"));
            list.add(carTypeId.get("carTypeName"));
            list.add(carTypeId.get("content"));
            list.add(quality.get("userLineId"));
            list.add(decimalFormat.format(Integer.valueOf(carTypeId.get("price"))));
        });
        m7Rv.setLayoutManager(new GridLayoutManager(this, 5));
        m7Rv.setAdapter(new recAdapter(list));
    }
}